package com.solocredit.finance.mvp

import android.view.View
import com.solocredit.finance.base.BaseFragment
import com.solocredit.finance.app.MyApp
import com.solocredit.finance.base.utils.ImageUtil
import com.solocredit.finance.databinding.IncludeMullaLicenseViewBinding
import com.solocredit.finance.utils.event.MullaEventData
import com.solocredit.finance.utils.event.MullaSubscriber
import com.solocredit.finance.utils.helper.MullaCustomConfigsHelper
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.MainScope

/**
 * MullaFlow
 * @Author wwdeng
 * @CreateTime: 2024/7/30 18:55
 * @Annotation：
 */
abstract class ProFm: BaseFragment(), MullaSubscriber, CoroutineScope by MainScope() {

    /**
     * 客服
     */
    fun showMullaKefuDialog(eventRemark: String = "",pName: String = "",pToken: String = ""){
        val proAct = context as ProAct
        proAct.showMullaKefuDialog(eventRemark,pName,pToken)
    }

    /**
     * 错误提示
     */
    fun showMullaErrorTipsDialog(tips: String,eventRemark: String = ""){
        val proAct = context as ProAct
        proAct.showMullaErrorTipsDialog(tips,eventRemark)
    }

    /**
     * 语言切换
     */
    fun showMullaLanguageDialog(eventRemark: String,isCancel: Boolean = true,isCancelTouch: Boolean = true,onSelectCallback: () -> Unit) {
        val proAct = context as ProAct
        proAct.showMullaLanguageDialog(eventRemark,isCancel,isCancelTouch,onSelectCallback)
    }

    /**
     * 网络错误提示
     */
    override fun showMullaNetworkErrorDialog(eventRemark: String, onRetryClick: () -> Unit) {
        val proAct = context as ProAct
        proAct.showMullaNetworkErrorDialog(eventRemark,onRetryClick)
    }

    /**
     * 获取当前用户VIP等级
     */
    fun getMullaUserVip(): Int{
        val proAct = context as ProAct
        return proAct.getMullaUserVip()
    }

    /**
     * 获取用户当前积分数 (从签到信息中获取)
     */
    fun getMullaUserPoints(): Int{
        val proAct = context as ProAct
        return proAct.getMullaUserPoints()
    }

    /**
     * 获取当前用户优惠券数量（从优惠券列表获取）
     */
    fun getMullaUserCouponCount(): Int{
        val proAct = context as ProAct
        return proAct.getMullaUserCouponCount()
    }

    /**
     * 牌照信息View
     */
    fun licenseView(): View{
        val proAct = context as ProAct
        return proAct.licenseView()
    }

    override fun onStart() {
        super.onStart()
        MyApp.app.publisher.register(this)
    }

    /**
     * 处理订阅事件
     */
    override fun onMullaEvent(event: MullaEventData) {

    }

    override fun onDestroy() {
        super.onDestroy()
        MyApp.app.publisher.detach(this)
    }
}